package com.xinfu.newproject.adapter.matter_repair_adapter;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.xinfu.newproject.R;
import com.xinfu.newproject.bean.matter_repair.RepairDetailBean;
import com.xinfu.newproject.ui.matter_repair.RepairDetailsActivity;
import com.xinfu.newproject.widget.picture.ViewPagerActivity;

/**
 *
 */
public class RepairDetailAdapter extends BaseQuickAdapter<RepairDetailBean.ResultBean.RepairStatusListBean, BaseViewHolder> {

    private String name, time;

    public RepairDetailAdapter() {
        super(R.layout.recycler_repair_detail);

    }

    public void detail(String name, String time) {
        this.name = name;
        this.time = time;
    }

    @Override
    protected void convert(BaseViewHolder helper, RepairDetailBean.ResultBean.RepairStatusListBean item) {
        ImageView imageView1 = helper.getView(R.id.recycler_repair_detail_iv1);
        ImageView imageView2 = helper.getView(R.id.recycler_repair_detail_iv2);
        ImageView imageView3 = helper.getView(R.id.recycler_repair_detail_iv3);
        ImageView imageView4 = helper.getView(R.id.recycler_repair_detail_iv4);
        switch (item.getStatus()) {
            case 100:
                helper.setText(R.id.recycler_repair_detail_status, "待受理");
                helper.getView(R.id.recycler_repair_detail_contents).setVisibility(View.GONE);
                helper.getView(R.id.recycler_repair_detail_ll).setVisibility(View.GONE);
                helper.setText(R.id.recycler_repair_detail_name, "报修人:" + name);
                helper.setText(R.id.recycler_repair_detail_time, "报修时间:" + time);
                break;
            case 200:
                helper.setText(R.id.recycler_repair_detail_status, "待维修");
                helper.getView(R.id.recycler_repair_detail_contents).setVisibility(View.GONE);
                helper.getView(R.id.recycler_repair_detail_ll).setVisibility(View.GONE);
                helper.setText(R.id.recycler_repair_detail_name, "处理人: " + item.getUserName());
                helper.setText(R.id.recycler_repair_detail_time, "处理时间: " + item.getCreateTime());
                break;
            case 300:
                helper.setText(R.id.recycler_repair_detail_status, "维修中");
                helper.getView(R.id.recycler_repair_detail_contents).setVisibility(View.GONE);
                helper.getView(R.id.recycler_repair_detail_ll).setVisibility(View.GONE);
                helper.setText(R.id.recycler_repair_detail_name, "处理人: " + item.getUserName());
                helper.setText(R.id.recycler_repair_detail_time, "处理时间: " + item.getCreateTime());
                break;
            case 500:
                helper.setText(R.id.recycler_repair_detail_status, "挂起中");
                helper.getView(R.id.recycler_repair_detail_contents).setVisibility(View.GONE);
                helper.getView(R.id.recycler_repair_detail_ll).setVisibility(View.GONE);
                helper.setText(R.id.recycler_repair_detail_name, "处理人: " + item.getUserName());
                helper.setText(R.id.recycler_repair_detail_time, "处理时间: " + item.getCreateTime());
                break;
            case 600:
                helper.setText(R.id.recycler_repair_detail_status, "已完成");
                helper.setText(R.id.recycler_repair_detail_name, "处理人: " + item.getUserName());
                helper.setText(R.id.recycler_repair_detail_time, "处理时间: " + item.getCreateTime());
                helper.setText(R.id.recycler_repair_detail_contents, "完成描述: " + item.getContents());
                helper.getView(R.id.recycler_repair_detail_contents).setVisibility(View.VISIBLE);
                helper.getView(R.id.recycler_repair_detail_ll).setVisibility(View.VISIBLE);
                if (item.getAttachFile() != null) {
                    if (item.getAttachFile().contains(";")) {
                        String[] imageSS = item.getAttachFile().split(";");
                        switch (imageSS.length) {
                            case 1:
                                Glide.with(mContext).load(imageSS[0]).asBitmap().error(R.mipmap.up_image_icon).into(imageView1);
                                imageView1.setVisibility(View.VISIBLE);
                                imageView2.setVisibility(View.GONE);
                                imageView3.setVisibility(View.GONE);
                                imageView4.setVisibility(View.GONE);
                                break;
                            case 2:
                                Glide.with(mContext).load(imageSS[0]).asBitmap().error(R.mipmap.up_image_icon).into(imageView1);
                                Glide.with(mContext).load(imageSS[1]).asBitmap().error(R.mipmap.up_image_icon).into(imageView2);
                                imageView1.setVisibility(View.VISIBLE);
                                imageView2.setVisibility(View.VISIBLE);
                                imageView3.setVisibility(View.GONE);
                                imageView4.setVisibility(View.GONE);
                                break;
                            case 3:
                                Glide.with(mContext).load(imageSS[0]).asBitmap().error(R.mipmap.up_image_icon).into(imageView1);
                                Glide.with(mContext).load(imageSS[1]).asBitmap().error(R.mipmap.up_image_icon).into(imageView2);
                                Glide.with(mContext).load(imageSS[2]).asBitmap().error(R.mipmap.up_image_icon).into(imageView3);
                                imageView1.setVisibility(View.VISIBLE);
                                imageView2.setVisibility(View.VISIBLE);
                                imageView3.setVisibility(View.VISIBLE);
                                imageView4.setVisibility(View.GONE);
                                break;
                            case 4:
                                Glide.with(mContext).load(imageSS[0]).asBitmap().error(R.mipmap.up_image_icon).into(imageView1);
                                Glide.with(mContext).load(imageSS[1]).asBitmap().error(R.mipmap.up_image_icon).into(imageView2);
                                Glide.with(mContext).load(imageSS[2]).asBitmap().error(R.mipmap.up_image_icon).into(imageView3);
                                Glide.with(mContext).load(imageSS[3]).asBitmap().error(R.mipmap.up_image_icon).into(imageView4);
                                imageView1.setVisibility(View.VISIBLE);
                                imageView2.setVisibility(View.VISIBLE);
                                imageView3.setVisibility(View.VISIBLE);
                                imageView4.setVisibility(View.VISIBLE);
                                break;
                        }
                    } else {
                        if (item.getAttachFile().length() > 5) {
                            Glide.with(mContext).load(item.getAttachFile()).asBitmap().into(imageView1);
                        } else {
                            helper.getView(R.id.recycler_repair_detail_ll).setVisibility(View.GONE);
                        }
                    }
                } else {
                    helper.getView(R.id.recycler_repair_detail_ll).setVisibility(View.GONE);
                }

                imageView1.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        Bundle bundle1 = new Bundle();
                        bundle1.putString("picture", item.getAttachFile());
                        bundle1.putInt("position", 0);
                        ((RepairDetailsActivity) mContext).startIntentActivityAnim(ViewPagerActivity.class, imageView1, bundle1);
                    }
                });
                imageView2.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        Bundle bundle1 = new Bundle();
                        bundle1.putString("picture", item.getAttachFile());
                        bundle1.putInt("position", 1);
                        ((RepairDetailsActivity) mContext).startIntentActivityAnim(ViewPagerActivity.class, imageView2, bundle1);
                    }
                });
                imageView3.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        Bundle bundle1 = new Bundle();
                        bundle1.putString("picture", item.getAttachFile());
                        bundle1.putInt("position", 2);
                        ((RepairDetailsActivity) mContext).startIntentActivityAnim(ViewPagerActivity.class, imageView3, bundle1);
                    }
                });
                imageView4.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        Bundle bundle1 = new Bundle();
                        bundle1.putString("picture", item.getAttachFile());
                        bundle1.putInt("position", 3);
                        ((RepairDetailsActivity) mContext).startIntentActivityAnim(ViewPagerActivity.class, imageView4, bundle1);
                    }
                });
                break;
            case 800:
                helper.setText(R.id.recycler_repair_detail_status, "已取消");
                helper.setText(R.id.recycler_repair_detail_contents, "关闭原因: " + item.getContents());
                helper.getView(R.id.recycler_repair_detail_contents).setVisibility(View.VISIBLE);
                helper.getView(R.id.recycler_repair_detail_ll).setVisibility(View.GONE);
                helper.setText(R.id.recycler_repair_detail_name, "处理人: " + item.getUserName());
                helper.setText(R.id.recycler_repair_detail_time, "处理时间: " + item.getCreateTime());
                break;
            case 900:
                helper.setText(R.id.recycler_repair_detail_status, "已评价");
                helper.getView(R.id.recycler_repair_detail_contents).setVisibility(View.VISIBLE);
                helper.getView(R.id.recycler_repair_detail_ll).setVisibility(View.VISIBLE);
                helper.setText(R.id.recycler_repair_detail_name, "评价人: " + name);
                helper.setText(R.id.recycler_repair_detail_time, "评价时间: " + item.getCreateTime());
                helper.setText(R.id.recycler_repair_detail_contents, "评价内容: " + item.getReviewContent());
                if (item.getCommentImg() != null) {
                    if (item.getCommentImg().contains(";")) {
                        String[] imageSS = item.getCommentImg().split(";");
                        switch (imageSS.length) {
                            case 1:
                                Glide.with(mContext).load(imageSS[0]).asBitmap().error(R.mipmap.up_image_icon).into(imageView1);
                                imageView1.setVisibility(View.VISIBLE);
                                imageView2.setVisibility(View.GONE);
                                imageView3.setVisibility(View.GONE);
                                imageView4.setVisibility(View.GONE);
                                break;
                            case 2:
                                Glide.with(mContext).load(imageSS[0]).asBitmap().error(R.mipmap.up_image_icon).into(imageView1);
                                Glide.with(mContext).load(imageSS[1]).asBitmap().error(R.mipmap.up_image_icon).into(imageView2);
                                imageView1.setVisibility(View.VISIBLE);
                                imageView2.setVisibility(View.VISIBLE);
                                imageView3.setVisibility(View.GONE);
                                imageView4.setVisibility(View.GONE);
                                break;
                            case 3:
                                Glide.with(mContext).load(imageSS[0]).asBitmap().error(R.mipmap.up_image_icon).into(imageView1);
                                Glide.with(mContext).load(imageSS[1]).asBitmap().error(R.mipmap.up_image_icon).into(imageView2);
                                Glide.with(mContext).load(imageSS[2]).asBitmap().error(R.mipmap.up_image_icon).into(imageView3);
                                imageView1.setVisibility(View.VISIBLE);
                                imageView2.setVisibility(View.VISIBLE);
                                imageView3.setVisibility(View.VISIBLE);
                                imageView4.setVisibility(View.GONE);
                                break;
                            case 4:
                                Glide.with(mContext).load(imageSS[0]).asBitmap().error(R.mipmap.up_image_icon).into(imageView1);
                                Glide.with(mContext).load(imageSS[1]).asBitmap().error(R.mipmap.up_image_icon).into(imageView2);
                                Glide.with(mContext).load(imageSS[2]).asBitmap().error(R.mipmap.up_image_icon).into(imageView3);
                                Glide.with(mContext).load(imageSS[3]).asBitmap().error(R.mipmap.up_image_icon).into(imageView4);
                                imageView1.setVisibility(View.VISIBLE);
                                imageView2.setVisibility(View.VISIBLE);
                                imageView3.setVisibility(View.VISIBLE);
                                imageView4.setVisibility(View.VISIBLE);
                                break;
                        }
                    } else {
                        if (item.getCommentImg().length() > 5) {
                            Glide.with(mContext).load(item.getCommentImg()).asBitmap().into(imageView1);
                        } else {
                            helper.getView(R.id.recycler_repair_detail_ll).setVisibility(View.GONE);
                        }
                    }
                } else {
                    helper.getView(R.id.recycler_repair_detail_ll).setVisibility(View.GONE);
                }

                imageView1.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        Bundle bundle1 = new Bundle();
                        bundle1.putString("picture", item.getCommentImg());
                        bundle1.putInt("position", 0);
                        ((RepairDetailsActivity) mContext).startIntentActivityAnim(ViewPagerActivity.class, imageView1, bundle1);
                    }
                });
                imageView2.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        Bundle bundle1 = new Bundle();
                        bundle1.putString("picture", item.getCommentImg());
                        bundle1.putInt("position", 1);
                        ((RepairDetailsActivity) mContext).startIntentActivityAnim(ViewPagerActivity.class, imageView2, bundle1);
                    }
                });
                imageView3.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        Bundle bundle1 = new Bundle();
                        bundle1.putString("picture", item.getCommentImg());
                        bundle1.putInt("position", 2);
                        ((RepairDetailsActivity) mContext).startIntentActivityAnim(ViewPagerActivity.class, imageView3, bundle1);
                    }
                });
                imageView4.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        Bundle bundle1 = new Bundle();
                        bundle1.putString("picture", item.getCommentImg());
                        bundle1.putInt("position", 3);
                        ((RepairDetailsActivity) mContext).startIntentActivityAnim(ViewPagerActivity.class, imageView4, bundle1);
                    }
                });
                break;
        }
        if (item.getPosition() == 0) {
            helper.setTextColor(R.id.recycler_repair_detail_status, mContext.getResources().getColor(R.color.blue_4a));
            helper.setTextColor(R.id.recycler_repair_detail_name, mContext.getResources().getColor(R.color.location_color));
            helper.setTextColor(R.id.recycler_repair_detail_time, mContext.getResources().getColor(R.color.location_color));
            helper.setTextColor(R.id.recycler_repair_detail_contents, mContext.getResources().getColor(R.color.location_color));
            helper.setImageResource(R.id.recycler_repair_detail_progress_iv, R.mipmap.repair_rot);
        } else {
            helper.setTextColor(R.id.recycler_repair_detail_status, mContext.getResources().getColor(R.color.gray_a5));
            helper.setTextColor(R.id.recycler_repair_detail_name, mContext.getResources().getColor(R.color.gray_a5));
            helper.setTextColor(R.id.recycler_repair_detail_time, mContext.getResources().getColor(R.color.gray_a5));
            helper.setTextColor(R.id.recycler_repair_detail_contents, mContext.getResources().getColor(R.color.gray_a5));
            helper.setImageResource(R.id.recycler_repair_detail_progress_iv, R.mipmap.repair_gray_rot);
        }

    }

}
